/*
@filename: initServer.sqf
Author:
	
	Quiksilver

Last modified:

	1/05/2014
	
Description:

	Server scripts such as missions, modules, third party and clean-up.
	
Credit:

	Invade & Annex 2.00 was created by Rarek [ahoyworld.co.uk] with countless hours of work, 
	and further developed by Quiksilver [allFPS.com.au] with countless hours more. 
	
	Contributors: Razgriz33 [AW], Jester [AW], Kamaradski [AW], David [AW], chucky [allFPS].
	
	ts.ahoyworld.co.uk:9987
	ts3.allfps.com.au:9992
	
	Please be respectful and do not remove/alter credits.
______________________________________________________*/


enableSaving [false, false];
enableSentences false;
enableTeamswitch false;	

//------------------------------------------------ Set up curator classes

curators = allCurators;
guestCurators = [];
adminCurators = curators - guestCurators;

//------------------------------------------------ Set up respawn positions

[west, "boat_spawn"] call BIS_fnc_addRespawnPosition;
[west, "pilot_spawn"] call BIS_fnc_addRespawnPosition;
[west, "fob_spawn"] call BIS_fnc_addRespawnPosition;

//------------------------------------------------ Handle parameters

for [ {_i = 0}, {_i < count(paramsArray)}, {_i = _i + 1} ] do {
	call compile format
	[
		"PARAMS_%1 = %2",
		(configName ((missionConfigFile >> "Params") select _i)),
		(paramsArray select _i)
	];
};

//-------------------------------------------------- Server scripts

call compile preProcessFile "\inidbi\init.sqf";															// Execute iniDBi functions
_null = [] execVM "scripts\stats\init_saveLoop.sqf";													// Stat saving loop
_null = [] execVM "scripts\stats\eventHandlers.sqf";													// Stat system event handlers
if (PARAMS_AO == 1) then { _null = [] execVM "mission\main\missionControl.sqf"; };						// Main AO
if (PARAMS_SideObjectives == 1) then { _null = [] execVM "mission\side\missionControl.sqf"; };			// Side Objectives
_null = [] execVM "scripts\eos\OpenMe.sqf";																// EOS (urban mission and defend AO)
_null = [] execVM "scripts\misc\airbaseDefense.sqf";													// Airbase air defense
_null = [] execVM "scripts\misc\clearBodies.sqf";														// clear bodies around island
_null = [] execVM "scripts\misc\clearItemsBASE.sqf";													// clear items around base
_null = [] execVM "scripts\misc\islandConfig.sqf";														// prep the island for mission
_null = [] execVM "scripts\misc\UAVfix.sqf";															// attempt UAV fix
_null = [] execVM "scripts\real_weather.sqf";															// Realistic Weather

// Initialise Curator Functions
{
	//--- Show map locations
	_x call bis_fnc_drawCuratorLocations;

	if (isserver) then {
		[_x,[-1,-2,0]] call bis_fnc_setcuratorvisionmodes;
	};
} foreach allcurators;

zeuslist = [
	"76561198031434864",		// Superxpdude
	"76561198011519046", 		// Darkbolt
	"76561197968794181",		// Anzu
	"76561198047135583", 		// Jordan
	"76561198032950755"			// Silverance
];

"adminrequest" addPublicVariableEventHandler {
	_unit = adminrequest;
	_adminUID = getPlayerUID _unit;
	if (_adminUID in zeusList) then {
		[_unit,"Curator"] call BIS_fnc_setUnitInsignia;
	};
	switch (_adminUID) do {
		case "76561198031434864": {_unit assignCurator zeus_superxpdude;};
		case "76561198011519046": {_unit assignCurator zeus_darkbolt;};
		case "76561197968794181": {_unit assignCurator zeus_anzu;};
		case "76561198047135583": {_unit assignCurator zeus_jordan;};
		case "76561198032950755": {_unit assignCurator zeus_silverance;};
	};
};

["zeusdisconnect", "onPlayerDisconnected", {
	switch (_uid) do {
		case "76561198031434864": {unAssignCurator zeus_superxpdude;};
		case "76561198011519046": {unAssignCurator zeus_darkbolt;};
		case "76561197968794181": {unAssignCurator zeus_anzu;};
		case "76561198047135583": {unAssignCurator zeus_jordan;};
		case "76561198032950755": {unAssignCurator zeus_silverance;};
	};
}] call BIS_fnc_addStackedEventHandler;

if (isDedicated) then {

	evo_updateMasterList = compile preprocessFile "\serverside\admins\synchronizeMasterList.sqf";
	call evo_updateMasterList;

	"evo_masterListUpdateRequest" addPublicVariableEventHandler {
		call evo_updateMasterList;
	};
} else {
	Evo_Admins = [(getPlayerUID player)];
};